package com.wanhai.base.dao;

import com.wanhai.util.RecordProcessBean;
import java.util.List;
import java.util.Map;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;

/**
 *
 * @author Richard Shih
 */
public interface IBaseDAO {

    /**
     * Query for Bean Return Bean
     *
     * @param sql
     * @param T
     * @param params
     * @return
     * @throws Exception
     */
    <T1> T1 queryForBean(String sql, Class<T1> T1) throws Exception;

    /**
     * Query for Bean Return Bean
     *
     * @param sql
     * @param T
     * @param params
     * @return
     * @throws Exception
     */
    <T1> T1 queryForBean(String sql, Class<T1> T1, Object... params) throws Exception;

    /**
     *
     * @param sql
     * @param T
     * @param bean
     * @return
     * @throws Exception
     */
    <T1> T1 queryForBean(String sql, Class<T1> T1, SqlParameterSource bean) throws Exception;

    /**
     * Query For Bean return Bean List
     *
     * @param sql
     * @param T
     * @param params
     * @return
     * @throws Exception
     */
    <T1> List<T1> queryForBeanList(String sql, Class<T1> T1) throws Exception;

    /**
     * Query For Bean return Bean List
     *
     * @param sql
     * @param T
     * @param params
     * @return
     * @throws Exception
     */
    <T1> List<T1> queryForBeanList(String sql, Class<T1> T1, Object... params) throws Exception;

    /**
     * User Spring JDBCTemplet maping bean to Query return Bean List
     *
     * ex. y
     *
     * @param sql
     * @param T
     * @param bean
     * @return
     * @throws Exception
     */
    <T1> List<T1> queryForBeanList(String sql, Class<T1> T1, SqlParameterSource bean) throws Exception;

    /**
     * Query Return Map
     *
     * @param sql
     * @param T
     * @param params
     * @return
     * @throws Exception
     */
    Map<String, Object> queryForMap(String sql) throws Exception;

    /**
     * Query Return Map
     *
     * @param sql
     * @param T
     * @param params
     * @return
     * @throws Exception
     */
    Map<String, Object> queryForMap(String sql, Object... params) throws Exception;

    /**
     * User Spring JDBCTemplet to Query return Map List
     *
     * @param sql
     * @param params
     * @return
     * @throws Exception
     */
    List<Map<String, Object>> queryForMapList(String sql) throws Exception;

    /**
     * User Spring JDBCTemplet to Query for params return Map List
     *
     * @param sql
     * @param params
     * @return List<Map<String,Object>>
     * @throws Exception
     */
    List<Map<String, Object>> queryForMapList(String sql, Object... params) throws Exception;

    int updateBean(String sql, Object... parems) throws Exception;

    /* DBHandler features below**************************************************************************************/

    /**
     * Update action. if vo bean did not contain rowid(vo.getRowid() is null),
     * it will process insert action.
     *
     * @param parameter VO bean object
     * @return int process records
     * @throws Exception
     */
    int update(RecordProcessBean parameter) throws Exception;

    /**
     * Delete action, VO bean must contain rowid. otherwise, delete will be
     * failure.
     *
     * @param parameter VO bean object
     * @return int delete records
     * @throws Exception
     */
    int delete(RecordProcessBean parameter) throws Exception;

    /**
     * VO Bean according to the values of query conditions, the default query
     * 200 records, but may be able to use setQuerySize (int size) to set the
     * maximum number of records in query if setQuerySize(-1), then it will
     * query all records.
     *
     * @param parameter VO bean object
     * @param clz type of return VO
     * @return List
     * @throws Exception
     */
    <T> List<T> query(RecordProcessBean parameter, Class<T> clz) throws Exception;

    /**
     * VO Bean according to the values of query conditions, the default query
     * 200 records, but may be able to use setQuerySize (int size) to set the
     * maximum number of records in query if setQuerySize(-1), then it will
     * query all records.
     *
     * @param parameter VO bean object
     * @param clz type of return VO
     * @param column String[] type, column list that need to be return.
     * @return List
     * @throws Exception
     */
    <T> List<T> query(RecordProcessBean parameter, Class<T> clz, String[] column) throws Exception;

    /**
     * VO Bean according to the values of query conditions, the default query
     * 200 records, but may be able to use setQuerySize (int size) to set the
     * maximum number of records in query if setQuerySize(-1), then it will
     * query all records.
     *
     * @param parameter VO bean object
     * @param clz type of return VO
     * @param column String[] type, column list that need to be return.
     * @param where extra where condition
     * @param orderby order by sequence
     * @return
     * @throws Exception
     */
    <T> List<T> query(RecordProcessBean parameter, Class<T> clz, String[] column, String where, String orderby) throws Exception;

    /**
     * VO Bean according to the values of query conditions and will query for
     * all vo bean fields Please note that setQuerySize () method is invalid on
     * this partialQuery),
     *
     * @param parameter VO bean.
     * @param clz type of return VO
     * @param pageNum Int, the first few pages
     * @param pageSize int, the number of records per page
     * @return ArrayList
     * @throws Exception
     */
    <T> List<T> partialQuery(RecordProcessBean parameter, Class<T> clz, int pageNum, int pageSize) throws Exception;

    /**
     * VO Bean according to the values of query conditions and will query for
     * special columns Please note that setQuerySize () method is invalid on
     * this partialQuery),
     *
     * @param parameter VO bean.
     * @param clz type of return VO
     * @param pageNum Int, the first few pages
     * @param pageSize int, the number of records per page
     * @param column String[] for query column list which defined in VO bean
     * @return ArrayList
     * @throws Exception
     */
    <T> List<T> partialQuery(RecordProcessBean parameter, Class<T> clz, int pageNum, int pageSize, String[] column) throws Exception;

    /**
     * VO Bean according to the values of query conditions and will query for
     * special columns Please note that setQuerySize () method is invalid on
     * this partialQuery),
     *
     * @param parameter VO bean.
     * @param clz type of return VO
     * @param pageNum Int, the first few pages
     * @param pageSize int, the number of records per page
     * @param column String[] for query column list which defined in VO bean
     * @param where extra where condition
     * @param orderby order by condition
     * @return
     * @throws Exception
     */
    <T> List<T> partialQuery(RecordProcessBean parameter, Class<T> clz, int pageNum, int pageSize, String[] column, String where, String orderby) throws Exception;

    /**
     * Based on the content of VO Bean inquiries, only return first record data,
     * the performance is higher than the query() method because only query
     * first record then will return.
     *
     * @param parameter VO bean
     * @return Object
     * @throws Exception
     */
    <T> T queryFirstRecord(RecordProcessBean parameter, Class<T> clz) throws Exception;
}
